package com.group9.handinhand.service.so;

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.ArrayUtils;

import com.group9.handinhand.dao.model.Event;
/**
 * Class for service of event
 *
 */
public class EventSO extends ActivitySO {

	private Date startingTime;
	
	private Date endingTime;
	
	private String location;
	
	private double latitude;
	
	private double longitude;
	
	private Set<UserSO> moderators = new HashSet<UserSO>();
	
	private Set<EventPostSO> posts = new HashSet<EventPostSO>();
	/**
	 * converts event model object
	 * @param ignoreProperties
	 * @return
	 */
	public Event convertToModelObject(String... ignoreProperties) {
		Event model = (Event) convert(new Event(),
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"community","creator","posts","service","goods","moderators"}));
		if( ! Arrays.asList(ignoreProperties).contains("community"))
			if(super.getCommunity() != null)
			model.setCommunity(super.getCommunity().convertToModelObject(new String[]{"moderators", "posts", "events","requests","offers"}));
		if( ! Arrays.asList(ignoreProperties).contains("creator"))
			if(super.getCreator() != null)
			model.setCreator(super.getCreator().convertToModelObject(new String[]{"socialUsers"}));
		if (!Arrays.asList(ignoreProperties).contains("posts"))
			for (EventPostSO post : posts) {
				model.getPosts().add(post.convertToModelObject());
			}
//		if( ! Arrays.asList(ignoreProperties).contains("service"))
//			if(super.getService() != null)
//				so.setService(super.getService().convertToServiceObject());
//		if( ! Arrays.asList(ignoreProperties).contains("goods"))
//			if(super.getGoods() != null)
//				so.setGoods(super.getGoods().convertToServiceObject());
//		if( ! Arrays.asList(ignoreProperties).contains("service"))
		if( ! Arrays.asList(ignoreProperties).contains("moderators"))
		for (UserSO user : moderators) {
			model.getModerators().add(user.convertToModelObject(new String[]{"socialUsers"}));
		}
		return model;
	}

	public Date getStartingTime() {
		return startingTime;
	}

	public void setStartingTime(Date startingTime) {
		this.startingTime = startingTime;
	}

	
	public Date getEndingTime() {
		return endingTime;
	}

	public void setEndingTime(Date endingTime) {
		this.endingTime = endingTime;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}
	
	public Set<UserSO> getModerators() {
		return moderators;
	}

	public void setModerators(Set<UserSO> moderators) {
		this.moderators = moderators;
	}

	@Override
	public String toString() {
		return "EventSO [startingTime=" + startingTime + ", endingTime="
				+ endingTime + ", location=" + location + ", latitude="
				+ latitude + ", longitude=" + longitude + "]";
	}

	public Set<EventPostSO> getPosts() {
		return posts;
	}

	public void setPosts(Set<EventPostSO> posts) {
		this.posts = posts;
	}

}
